/* 
 * File:   EnvCell.h
 * Author: Ben
 *
 * Created on November 2, 2012, 1:30 PM
 */

#ifndef ENVCELL_H
#define	ENVCELL_H

/**
 * 1) Needs to store particles
 * 2) Synchronization stuff?
 * 3) Add/remove particles
 */

#include "Particle.h"
#include <vector>
#include <pthread.h>


class EnvCell{
private:
    /**
     * List of all particles in given cell
     */
    std::vector<Particle*> m_ParticleContainer;
    /**
     * Number of agents in this cell
     */
    int numAgentsPresent;
    /**
     * Mutexes for each data member of this class
     */
    static pthread_mutex_t agentPresentLocker;
    static pthread_mutex_t particleContainerLocker;
    
    
    
public:
    /**
     * Default constructor
     */
    EnvCell();
    /**
     * Default destructor
     */
    ~EnvCell();
    /**
     * Takes the particle at the end of the m_ParticleContainer vector.
     * Modifies m_ParticleContainer
     * @return The particle at the end of the vector
     */
    Particle* takeParticle();
    /**
     * Pushes a new particle onto m_ParticleContainer
     * @param newParticle Particle to add
     */
    void placeParticle(Particle* newParticle);
    /**
     * Determines total number of particles in cell
     * @return Number of particles in cell
     */
    int getNumParticles() { return m_ParticleContainer.size(); }
    /**
     * Used for testing. Prints contents of cell
     */
    void printContainer();
    /**
     * Deletes all particles in cell. Modifies m_ParticleContainer
     */
    void cleanCell(); 
    /**
     * Particle ID's found in this cell are removed from the assignedIDs 
     * parameter. 
     * @param assignedIDs List of all assigned IDs unaccounted for at this time
     * @return Updated assignedIDs vector
     */
    std::vector<int> accountCell(std::vector<int> assignedIDs);
    /**
     * Determines total number of agents in this cell
     * @return Number of agents in this cell
     */
    int agentsPresent() { return numAgentsPresent; }
    /**
     * Called by agents to signal an agent has arrived
     */
    void agentArrived();
    /**
     * Called by agents to signal an agent has departed.
     */
    void agentDeparted();
};

#endif	/* ENVCELL_H */

